{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "f2fa0e33",
   "metadata": {},
   "source": [
    "# 第零章 Blender 开发环境配置"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "74321f42",
   "metadata": {},
   "source": [
    "## 一、环境安装"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2b27e057",
   "metadata": {},
   "source": [
    "\n",
    "### 1.安装Blender \n",
    "\n",
    "位置如： F:\\\\Blender\\\\blender.exe \n",
    "\n",
    "### 2.安装Blender插件：\n",
    "\n",
    "- Blender Development \n",
    "- Blender Python Code Templates 用于生成插件模板程序\n",
    "\n",
    "#### 2.1设置内指定用于自动提示 第三方插件 fake_bpy_modules_2.xx \n",
    "\n",
    "- 下载地址 https://github.com/nutti/fake-bpy-module/releases\n",
    "如 Blender2.93 则下载文件 fake_bpy_modules_2.93-20210701.zip\n",
    "将文件解压到本地目录 如：F:\\fake_bpy_modules_2.93-20210701 \n",
    "\n",
    "### 3.打开 VSCode 设置  切换到文本模式\n",
    "\n",
    "在配置文件中，填入如下内容：\n",
    "\n",
    "```json\n",
    "\n",
    "#此处是本地blender启动程序路径\n",
    " \"blender.executables\": [\n",
    "        {\n",
    "            \"path\": \"F:\\\\Blender\\\\blender.exe\",  \n",
    "            \"name\": \"\",\n",
    "            \"isDebug\": false\n",
    "        }\n",
    " ],\n",
    "\n",
    "#此处是第三方插件包目录路径 用于blender的自动补全\n",
    " \"python.autoComplete.extraPaths\": \n",
    " [\n",
    "     \"F:\\\\fake_bpy_modules_2.93-20210701\"    \n",
    " ],\n",
    "#此处是第三方插件包目录路径 用于blender的分析\n",
    " \"python.analysis.extraPaths\": [\n",
    "     \"F:\\\\fake_bpy_modules_2.93-20210701\"    \n",
    " ],\n",
    "\n",
    "``` \n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0211c6e3",
   "metadata": {},
   "source": [
    "## 二、初次测试 "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f9684c31",
   "metadata": {},
   "source": [
    "\n",
    "#### 此时所有Blender有关的常用工具安装完成 接下来进行测试\n",
    "\n",
    "### 1.建立插件文件夹\n",
    "\n",
    "目录位置如： F:\\Blender\\plugin\\test1\\\n",
    "在此插件目录打开VSCode ，并保证文件夹下是空的\n",
    "\n",
    "### 2.根据模板生成插件python脚本文件\n",
    "\n",
    "打开VSCode按下快捷键 Ctrl+Shift+P ,在VSCode上标题部位弹出栏目\n",
    "在栏目内搜索Blender 可以 得到Blender的有些功能 如 ：\n",
    "Blender:New Addon , Blender:Start 等\n",
    "\n",
    "此处我们选择 Blender:New Addon\n",
    "然后在模板处选择 Simple 模板即可\n",
    "\n",
    "随后会引导用户创建\n",
    "插件名称\n",
    "插件作者\n",
    "插件需要放入的文件夹（此处通常会直接给出选项，若此处弹窗可能因为文件夹非空）\n",
    "\n",
    "实例如下：\n",
    "- 插件名称 test\n",
    "- 插件作者 sky92\n",
    "- 插件路径 F:\\Blender\\plugin\\test1\\\n",
    "\n",
    "### 3.代码编辑\n",
    "\n",
    "插件文件创建之后，会在插件文件夹内生成一个 \\__init__.py 文件 \n",
    "\n",
    "文件内容如下：\n",
    "\n",
    "```python\n",
    "bl_info = {\n",
    "    \"name\" : \"test\",\n",
    "    \"author\" : \"sky\",\n",
    "    \"description\" : \"\",\n",
    "    \"blender\" : (2, 80, 0),\n",
    "    \"version\" : (0, 0, 1),\n",
    "    \"location\" : \"\",\n",
    "    \"warning\" : \"\",\n",
    "    \"category\" : \"Generic\"\n",
    "}\n",
    "\n",
    "#在blender SDK加载界面选择加载和取消加载时的动作\n",
    "def register():\n",
    "    ...\n",
    "\n",
    "def unregister():\n",
    "    ...\n",
    "\n",
    "```\n",
    "将上述的 ``` def register(): ```下的```...```替换为：\n",
    " ``` print(\"hello_blender\") ```\n",
    "\n",
    "将上述的 ``` def unregister(): ```下的```...```替换为：\n",
    " ``` print(\"bye_blender\") ```\n",
    " \n",
    " \n",
    "两者表示为在blender SDK加载界面选择加载和取消加载时的动作\n",
    "\n",
    "#### 此时我们的测试代码部分完成了，接下来是打开Blender验证的时候\n",
    "\n",
    "### 4.验证插件\n",
    "\n",
    "\n",
    "同样\n",
    "VSCode按下快捷键 Ctrl+Shift+P ,在VSCode上标题部位弹出栏目  \n",
    "\n",
    "在栏目内搜索Blender 可以 得到Blender的有些功能 如 ：  \n",
    "Blender:New Addon , Blender:Start 等  \n",
    "\n",
    "此处我们选择 Blender:Start  \n",
    "并在列表中选择我们的Blender的启动路径   \n",
    "如果在 VSCode 设置时有多个Blender安装路径 ，则会在选项内出现多路径列表  \n",
    "\n",
    "选择后Blender就启动\n",
    "\n",
    "启动时需要注意看VSCode的调试控制台是否有打印出字符串 hello_blender     \n",
    " 若有，那么我们已经成功一半了    \n",
    " \n",
    "\n",
    "进入Blender的界面后，\n",
    "[菜单栏] --  [编辑] -- [偏好设置] ， 打开Blender偏好设置界面  \n",
    "左侧栏目选择[插件]，搜索[test]  \n",
    "此时会找到用于自定义的插件 [test]  \n",
    "\n",
    "将标题前的勾选框内的勾选取消，再观察VSCode的调试控制台是否有打印出字符串 bye_blender    \n",
    " 若有，则配置环境已经完备；\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "027530e5",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "30f4034a",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5592387a",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9bed95d9",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d302ad33",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
